<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>

<div id="app">
    
   
  请输入需要查找的数:<input v-model="target"><button @click="find()">点击查找</button>
  
  <!-- {{num}} -->
  <!-- <button @click="find(target,arr)">点击查找<input type="text" v-model="target" ></button> -->
    
</div>

<script>
  const { createApp } = Vue
  
  createApp({
    data() {
      return {
       num:0,
       target:0 
      }
    },
    methods:{
        find(target,shuju){
          // var shuju=[11,12,13,14,15,16,17,18,19]
          var shuju=[52,2,62,22,10,5,90,31,60,50,10]
          shuju = shuju.sort(function(a,b){
          return a - b; 
          })

            
            var start=0
            var end = shuju.length-1
            
            // var target= +prompt("输入你要查找的元素：")
            var target = this.target
            var num = 0
            
            while(start<=end){
                var mid = Math.floor((end+start)/2)
                if(target >shuju[end] || target < shuju[start]){
                  
                  console.log("不存在")
                        break;
                }
                
                num++
                if(target == shuju[mid]){
                  
                  console.log(num+"次")
                    return 0 
                }else if(target >shuju[mid]){
                    start = mid+1
                }else{
                    end = mid -1
                }
                
                
            } 
           
        }
    }
  }).mount('#app')
</script>
